from django.conf.urls.defaults import *
from ocw.ntu.models import Teacher, Course, DailyQuote, Lecture
from django.views.generic.simple import direct_to_template
from django.conf import settings
from ocw.ntu.RSSFeeds import LatestEntries#, LatestEntriesByCategory

import os.path
import os
# --------------------------------------
# Provide site specific directory paths
# Source: http://blog.cottee.org/2008/04/django-settings-file.html
# --------------------------------------
ROOT_DIR_PATH = os.path.realpath(os.curdir)
#Example: 
#"%s/ntu/images" % ROOT_DIR_PATH

info_dict = {
    'queryset': Course.objects.all(),
}

lecture_dict = {
    'queryset': Lecture.objects.all(),
}

quote_dict = {
    'daily_quote': DailyQuote.objects.all(),
}

feeds = {
    'latest': LatestEntries,
}

urlpatterns = patterns('',
    # Example:
    # (r'^ntu/', include('ntuocw.foo.urls')),

    # Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),
     #(r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/home/student/96/b96123/django/projects/ocw/ntu/images'}),
     (r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': "%s/ntu/images" % ROOT_DIR_PATH}),
     (r'^$', 'ocw.ntu.views.index'),
     (r'^index.html$', 'ocw.ntu.views.index'),
     (r'^threadedcomments/', include('threadedcomments.urls')),
     (r'^comments/$', 'ocw.ntu.views.course_detail'),

     #(r'^ocw/media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/home/student/96/b96123/django/projects/ocw/media'}),
     (r'^ocw/media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': "%s/media" % ROOT_DIR_PATH}), # TODO: or /ocw/media? 

      # View Course Details
     (r'^viewCourse/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
     
     # Search all courses
     (r'^search/$', 'ocw.ntu.views.search'),

     # RSS Feeds
     (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
     (r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),

     
     # Under construction page 
     (r'^tbd.html$', direct_to_template, {'template': 'tbd.html'}, info_dict),	

     #----------------------------------------
     # Navigation Links
     #(r'^courses.html$', direct_to_template, {'template': 'courses.html'}, info_dict),	
     (r'^courses.html/$', 'django.views.generic.list_detail.object_list', dict(info_dict, template_name='ntu/courses.html')),


     # Video URLs
     (r'^video.html$', direct_to_template, {'template': 'video.html'}, info_dict),	

     # Video Trailer
     (r'^trailer$', direct_to_template, {'template': 'playTrailer.html'}, info_dict),
     
     # View Single item 
     (r'^viewVideo/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', dict(lecture_dict, template_name='ntu/showVideo.html')),
     # to refactor
     #(r'^playVideo/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', dict(lecture_dict, template_name='ntu/showVideo.html')),
     ##ok(r'^playVideo.html$', direct_to_template, {'template': 'playVideo.html'}, info_dict),	
     # TODO: make it dynamic
     (r'^playVideo/sysprog$', direct_to_template, {'template': 'playVideo_sysprog.html'}, info_dict),	
     (r'^playVideo/oosd$', direct_to_template, {'template': 'playVideo_oosd.html'}, info_dict),	
     (r'^playVideo/mediadesign$', direct_to_template, {'template': 'playVideo_mediadesign.html'}, info_dict),	
     (r'^playVideo/elearning$', direct_to_template, {'template': 'playVideo_elearning.html'}, info_dict),	
     (r'^playVideo/freshmanenglish$', direct_to_template, {'template': 'playVideo_freshmanenglish.html'}, info_dict),	
     
     # Video Upload feature 
     (r'^upload.html$', direct_to_template, {'template': 'upload.html'}, info_dict),	
     (r'^videoupload$', 'ocw.ntu.views.video_upload'),	

     #(r'^viewall/$', 'django.views.generic.list_detail.object_list', info_dict),
     #(r'^index.html/$', 'django.views.generic.date_based.archive_index', dict(info_dict,num_latest=5)),

)
